package domain

import (
	"context"
	"fmt"
	"time"

	"github.com/lab-online/internal/lab/entity"
	"github.com/lab-online/pkg/logger"
)

func (d *Domain) CreateUploadURL(lab entity.LabEntity) (string, error) {
	if err := d.checkEligibility(lab); err != nil {
		return "", err
	}

	bucketName := fmt.Sprintf("lab-%d", lab.GetExperimentID())
	objectKey := fmt.Sprintf("classes/%d/students/%s", lab.GetClassID(), lab.GetStudent())
	logger.Debug("create upload url", bucketName, objectKey)
	return d.oss.PresignedPutObjectURL(context.Background(), bucketName, objectKey, time.Second*60*3)
}
